home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Source / SkelGetRectDevice.c < prev    next >
Text File  |  1996-01-17  |  3KB  |  95 lines

  1. /*
  2.  * Given a rectangle, determine the following values:
  3.  * - Which device contains more of the rectangle than any other
  4.  * - The device rectangle (this includes the menu bar area if the device
  5.  * is the main device)
  6.  * - Whether or not the device is the main device
  7.  *
  8.  * These values are stuffed into the arguments, which are passed as
  9.  * variable addresses.  If you're not interested in a particular value,
  10.  * pass nil for the corresponding argument.
  11.  *
  12.  * The return value if true if the rectangle overlaps some device,
  13.  * false if it lies outside all devices.  If the rectangle overlaps no
  14.  * device, non-nil arguments are filled in with the main device, the main
  15.  * device rect, and true, respectively.  This is useful, e.g., for callers
  16.  * that may want to reposition a window if its content rectangle isn't
  17.  * visible on some monitor.
  18.  *
  19.  * The returned device value will be nil on systems that don't have GDevices
  20.  * (i.e.,, that don't support Color QuickDraw), even if the function result
  21.  * is true.
  22.  *
  23.  * References: TN TB 30.
  24.  */
  25.  
  26. # include    "TransSkel.h"
  27.  
  28.  
  29. pascal Boolean
  30. SkelGetRectDevice (Rect *rp, GDHandle *rGD, Rect *devRect, Boolean *isMain)
  31. {
  32. GDHandle    gd, curGD;
  33. Rect        gdRect, curRect, iSectRect;
  34. long        maxArea, area;
  35. Boolean        main = false;
  36. Boolean        result;
  37.         
  38.     gd = (GDHandle) nil;                /* no device for rectangle known yet */
  39.  
  40.     if (!SkelQuery (skelQHasColorQD))
  41.     {
  42.         /*
  43.          * No Color QuickDraw implies only one screen, which is therefore
  44.          * the main device.  Test rectangle against full screen, setting
  45.          * result true if they intersect.
  46.          */
  47.         main = true;
  48.         gdRect = SkelQD (screenBits.bounds);
  49.         result = SectRect (rp, &gdRect, &iSectRect);
  50.     }
  51.     else
  52.     {
  53.         /* determine device having maximal overlap with r */
  54.  
  55.         maxArea = 0;
  56.         for (curGD = GetDeviceList (); curGD != (GDHandle) nil; curGD = GetNextDevice (curGD))
  57.         {
  58.             /* only consider active screen devices */
  59.             if (!TestDeviceAttribute (curGD, screenDevice)
  60.                     || !TestDeviceAttribute (curGD, screenActive))
  61.                 continue;
  62.             curRect = (**curGD).gdRect;
  63.             if (!SectRect (rp, &curRect, &iSectRect))
  64.                 continue;
  65.             area = (long) (iSectRect.right - iSectRect.left)
  66.                     * (long) (iSectRect.bottom - iSectRect.top);
  67.             if (maxArea < area)
  68.             {
  69.                 maxArea = area;
  70.                 gd = curGD;
  71.                 gdRect = curRect;
  72.                 result = true;    /* rectangle overlaps some device */
  73.             }
  74.         }
  75.         if (gd == (GDHandle) nil)    /* rectangle overlaps no device, use main */
  76.         {
  77.             gd = GetMainDevice ();
  78.             gdRect = (**gd).gdRect;
  79.             result = false;
  80.         }
  81.         main = (gd == GetMainDevice ());
  82.     }
  83.  
  84.     /* fill in non-nil arguments */
  85.  
  86.     if (rGD != (GDHandle *) nil)
  87.         *rGD = gd;
  88.     if (devRect != (Rect *) nil)
  89.         *devRect = gdRect;
  90.     if (isMain != (Boolean *) nil)
  91.         *isMain = main;
  92.  
  93.     return (result);
  94. }
  95.